package lb03ansatztilo;

public class Uniform extends RandVar{
	
	private long lowerBound;
	private long upperBound;
	
	public Uniform(long lowerBound, long upperBound) {
		initVariables(lowerBound, upperBound);
	}
	
	private void initVariables(long lowerBound, long upperBound) {
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
		setValueGenerator(new StRNG(1));
		createRV();
		calcVarianz();
		calcErwartungwert();
		calcVDF();
		calcVF();
	}

	private void calcVF() {
		setVf((getRV() - lowerBound) / (upperBound - lowerBound));
	}

	private void calcVDF() {
		setVDF(1 / (upperBound - lowerBound));
	}

	private void calcErwartungwert() {
		setErwartungwert((lowerBound + upperBound) / 2);
	}
	
	private void createRV(){
		long rv = randomValToVar(getRandomNumber());
		setRv(rv);
	}
		
	private void calcVarianz() {
		setVarianz(((upperBound - lowerBound) * (upperBound - lowerBound) / 12));
	}
	
	private long randomValToVar(long randomVal){
		long randomVar = lowerBound + (upperBound - lowerBound) * randomVal; 
		return randomVar;
	}
	
	@Override
	protected long getVarianz() {
		return super.getVarianz();
	}
	
	@Override
	protected long getErwartungwert() {
		return super.getErwartungwert();
	}
	
	@Override
	protected long getRV() {
		return super.getRV();
	}

}
